package com.izocen.rules.core.engine;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.izocen.rules.common.EngineResponse;
import com.izocen.rules.core.rule.RuleUnit;

/**
 *@ClassName DefaultLessRuleEngine
 * @Description: 
 * @Author pengyongjun
 * @Date 2020年6月19日
 */
public class DefaultLessRuleEngine extends AbstractLessRulesEngine{

	@Override
	public EngineResponse fire(Map<String, String> fact) {
		Iterator<RuleUnit> it =	this.ll.iterator();
		Map<String,List<String>> resultMap = new HashMap<String,List<String>>();
		while(it.hasNext()) {
			RuleUnit ru = it.next();
			boolean  result = ru.fire(fact);//单个规则器匹配
			if(result) {
				String groupId = ru.getGroupId();
				String id      = ru.getId();
				List<String> ruleIdList = resultMap.get(groupId);
				if(ruleIdList == null) {
					ruleIdList = new ArrayList<String>();
				}
				ruleIdList.add(id);
				resultMap.put(groupId, ruleIdList);
				break;
			}
		}
		return this.assebleFireResult(resultMap);
	}


}
